# @Time:        2024/7/5 上午8:54
# @USER:        lihuizhuo
# @Site:        www.swust.edu.cn
# @File:        M
# @Software:    PyCharm
# @license:     Copyright(C), swust
# @Author:      huizhuo
# @Email:       huizhuoli@foxmail.com
# @Version:     V1.1.0
import pygame


def load_run_man_image():
    """
    加载跑步人物的图片
    :return: 图片列表
    """
    image_list = []
    for i in range(1, 10):
        image = pygame.image.load("resources/images/welcome/" + str(i) + "-1.png")
        print("resources/images/welcome/" + str(i) + "-1.png")
        image_list.append(image)

    return image_list


def game_run():
    """
    游戏运行
    :return:
    """
    # pygame setup
    pygame.init()
    # set up the display 窗口
    screen = pygame.display.set_mode((1280, 720))
    clock = pygame.time.Clock()
    running = True
    man_image_list = load_run_man_image()
    backgroud = pygame.image.load("resources/images/welcome/welcome.jpg")

    image_index = 0
    x = 20
    y = 20

    while running:
        # poll for events
        # pygame.QUIT event means the user clicked X to close your window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        # fill the screen with a color to wipe away anything from last frame
        # screen.fill("purple")
        #
        screen.blit(backgroud, (0, 0))
        screen.blit(man_image_list[image_index], (x, y))

        # RENDER YOUR GAME HERE

        # flip() the display to put your work on screen
        pygame.display.flip()

        clock.tick(20)  # limits FPS to 60

        image_index += 1
        if image_index > 8:
            image_index = 0

        x += 10
        y += 10
        if x > 1280:
            x = 20
        if y > 720:
            y = 20

    pygame.quit()


if __name__ == '__main__':
    game_run()
